import { Plugin } from '../../store/PluginInterface';
import { readColumnData } from './googleSheetsEntry.ts';

declare const electronAPI: any;

const GoogleSheetsPlugin: Plugin = {
    id: 'google-sheets',
    name: 'Google Sheets',
    category: 'Auchan',
    version: '1.0.0',
    description: 'Google Sheets Entry',
    downloadUrl: 'http://10.169.128.20/files/plugins/google-sheets.zip',

    init: () => {
        console.log('Google Sheets Plugin initialized');
    },


    run: async () => {
        try {
            // 通过IPC获取存储的sheet IDs
            const sheetIds = await electronAPI.getSheetIds();
            const results = [];

            for (const sheetId of sheetIds) {
                const data = await readColumnData(sheetId, '106!F56:F59');
                results.push(data);
                console.log(`Google Sheets data for ${sheetId}:`, data);
            }

            return results;
        } catch (error) {
            console.error('Error running Google Sheets Plugin:', error);
            throw error;
        }
    },
};

export default GoogleSheetsPlugin;